import java.util.Arrays;

public class leetcode {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int sum=0;
        for(int c=nums.length-1;c>1;c--){
            int a=0;
            int b=c-1;

            while(a<b){
                if(nums[a]+nums[b]>nums[c]){
                    sum+=b-a;
                    b--;
                }else{
                    a++;
                }
            }
        }
        return sum;
    }
}
